package com.flw.eslab.action.admin;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.stereotype.Controller;

import com.flw.eslab.dto.PageInfo_Dto;
import com.flw.eslab.dto.Resource_Dto;
import com.flw.eslab.service.ResourceManager;
import com.flw.eslab.service.UserManager;


@Controller
@Results({
	@Result(name = "tolist", location = "info?jump_url=list", type = "redirect"),
	@Result(name = "toAdd", location = "info?jump_url=add", type = "redirect")})
public class ResourceAction extends CommonAction {
	private Resource_Dto resource_Dto = new Resource_Dto();
	@Resource
	private ResourceManager resourceManager;
	private PageInfo_Dto pageInfo_Dto;

	public PageInfo_Dto getPageInfo_Dto() {
		return pageInfo_Dto;
	}

	public void setPageInfo_Dto(PageInfo_Dto pageInfo_Dto) {
		this.pageInfo_Dto = pageInfo_Dto;
	}

	public ResourceManager getResourceManager() {
		return resourceManager;
	}

	public String add() {
		if(resourceManager.add(resource_Dto.toResource())){
			session.put("msg", "报告添加成功");
			return "tolist";
		}
		else{
			session.put("msg", "报告添加不成功");
			return "toAdd";
		}
	}
	
	public String delete(){
		if(resourceManager.delect(resource_Dto.toResource())){
			session.put("msg", "报告删除成功");
			return "tolist";
		}else{
			session.put("msg", "报告删除不成功");
			return "tolist";
		}
	}

	public String load() {
		
		setPageInfo_Dto(resourceManager.load(pageInfo_Dto));
		session.put("pageInfo_Dto", pageInfo_Dto);
		return "success";
	}

	public String update() {
		
		if(resourceManager.modify(resource_Dto.toResource())){
			session.put("msg", "报告删除成功");
			return "tolist";
		}else{
			session.put("msg", "报告删除不成功");
			return "tolist";
		}
	}
	/*---------------------------------*/
	public Resource_Dto getResource_Dto() {
		return resource_Dto;
	}

	public void setResource_Dto(Resource_Dto resource_Dto) {
		this.resource_Dto = resource_Dto;
	}

	public void setResourceManager(ResourceManager resourceManager) {
		this.resourceManager = resourceManager;
	}

}
